package com.cndw.kungfu.business;

import org.springframework.beans.factory.annotation.Autowired;

import com.cndw.kungfu.comm.GmCommand;
import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.model.DataStaticCenter;
import com.cndw.kungfu.model.business.IPlayerManager;
import com.cndw.kungfu.model.pvp.api.CommApiClient;
import com.cndw.rpg.annotation.Controller;
import com.cndw.rpg.annotation.UnAuth;
import com.cndw.rpg.framework.ResponseMessage;
import com.cndw.rpg.framework.Session;
import com.cndw.rpg.framework.SessionHolder;

/**
 * 外部接口
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2011-6-8 上午11:14:54
 */
@Controller
public class BusinessApiOnline {

	@Autowired
	private IPlayerManager playerManager;

	@UnAuth
	@GmCommand
	public ResponseMessage getOnlineCounts(Session session, String sign, int type) {
		switch (type) {
		case 1:
			return ResponseMessage.getSuccMessage(SessionHolder.getInstance().onlineNums());
		case 2:
			return ResponseMessage.getSuccMessage(playerManager.getOnlineCounts()); // 所有玩家
		case 3:
			return ResponseMessage.getSuccMessage(playerManager.getOnlineFilterCounts()); // 过滤24小时内注册的
		case 11:
			return ResponseMessage.getSuccMessage(DataStaticCenter.flashMJOnLineNum());
		default:
			return ResponseMessage.getSuccMessage(false);
		}
	}

	@UnAuth
	@GmCommand
	public ResponseMessage getServerStatus(Session session, String sign) {
		if (ConstantsConfig.isSysClosed()) {
			return ResponseMessage.getSuccMessage(-1);
		} else {
			return ResponseMessage.getSuccMessage(SessionHolder.getInstance().onlineNums());
		}
	}

	@UnAuth
	@GmCommand
	public ResponseMessage getUserStatus(Session session, String sign, int type, String uname) {

		if (type == 0 && ConstantsConfig.isSysClosed()) {
			return ResponseMessage.getSuccMessage(2);
		}

		long playerId = Context.getPlayerServer().getPlayerIdByAccount(uname);
		if (playerId == 0) {
			return ResponseMessage.getSuccMessage(0);
		} else {
			Player player = Context.getPlayerServer().getByPlayerId(playerId);
			return ResponseMessage.getSuccMessage("1:" + player.getPlayerName());
		}
	}
	
	@UnAuth
	@GmCommand
	public ResponseMessage getMJOnlinAll(Session session,String sign){
		return ResponseMessage.getSuccMessage(CommApiClient.allMJOnLine());
	}
	
	
}
